package com.jiaz.controller;

import com.jiaz.service.CategoryService;
import com.jiaz.service.CheckInService;
import com.jiaz.service.PostionService;
import com.jiaz.service.UserService;
import com.jiaz.untils.ResponseBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jiajiazi
 * @version 1.0
 * @date 2022/5/5 16:41
 */
@RestController
@Slf4j
@RequestMapping("/panel**")
public class PanelController {

    @Autowired
    private UserService userService;
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private PostionService postionService;
    @Autowired
    private CheckInService checkInService;

    @RequestMapping("/checkUserId")
    public ResponseBean checkUserId(Integer userId) {
        if (userId == null || userId == 0) {
            return ResponseBean.error(4008, "参数错误(空值或为0)");
        }
        return userService.getUserById(userId);
    }

    /**
     * 距离坐标最近五个点
     *
     * @param lat
     * @param lon
     * @return
     */
    @RequestMapping("/getClosePostionList")
    public ResponseBean getClosePostionList(Double lat, Double lon) {
        if (lat == null || lon == null) {
            return ResponseBean.error(4008, "参数错误(空值)");
        }
        return postionService.getClosePostionList(lat, lon);
    }

    @RequestMapping("/getPostionFreq")
    public ResponseBean getPostionFreq(Double lat, Double lon, Integer userId) {
        if (lat == null || lon == null) {
            return ResponseBean.error(4008, "参数错误(空值)");
        }
        return postionService.getPostionFreq(lat, lon, userId);
    }

    @RequestMapping("/getTotalUser")
    public ResponseBean getTotalUser() {
        return userService.getTotalUser();
    }

    @RequestMapping("/getUserBase")
    public ResponseBean getUserBase(Integer userId) {
        if (userId == null || userId == 0) {
            return ResponseBean.error(4008, "参数错误(空值或为0)");
        }
        return userService.getUserBase(userId);
    }

    @RequestMapping("/getCategoryBase")
    public ResponseBean getCategoryBase() {

        return categoryService.getCategoryBase();
    }

    @RequestMapping("/getCurrentTrace")
    public ResponseBean getCurrentTrace(Double lat, Double lon) {

        return checkInService.getCurrentCheckInTrace(lat, lon);
    }

    @RequestMapping("/getAllTrace")
    public ResponseBean getAllTrace() {

        return checkInService.getAllCheckInTrace();
    }

    @RequestMapping("/getHeatMap")
    public ResponseBean getHeatMap() {

        return postionService.getAllHeatMap();
    }


}
